var app = getApp();
var util = require("../../utils/util.js");
var siteinfo = require('../../siteinfo.js');
Page({
    data: {
        userName: '', //姓名
        ticketNumber: '', //准考证号
        idNumber: '', //考生编号
        examinationBatchList: null,
        examinationNameList: null,
        examinationIdList: null,
        index: 0
    },

    onLoad: function (options) {

    },
    onShow: function () {
        var _this = this
        app._get(siteinfo.selExaminationBatch, {},
            function (result) {
                var nameList = ['--请选择考试批次--'];

                var idList = [''];
                result.data.forEach(function (item, index) {
                    if (!item.name.split('师资')[0]) {
                        item.name = item.name.split('师资')[1]
                    }
                    nameList.push(item.name)
                    idList.push(item.id)
                })
                _this.setData({
                    examinationBatchList: result.data,
                    examinationNameList: nameList,
                    examinationIdList: idList
                })
            })
    },
    getExaminationBatch: function (e) {
        this.setData({
            index: e.detail.value
        })
    },
    //登录-获取姓名
    getUserName: function (e) {
        var value = e.detail.value;
        this.setData({
            userName: value
        });
    },
    //登录-获取准考证号
    getTicketNumber: function (e) {
        var value = e.detail.value;
        this.setData({
            ticketNumber: value
        });
    },
    //密码登录-获取密码
    getIdNumber: function (e) {
        var value = e.detail.value;
        this.setData({
            idNumber: value
        });
    },
    //登录
    login: function (e) {
        var _this = this;
        if (0 == _this.data.index) {
            app.showError('请选择考试批次');
            return false;
        }
        if ("" == _this.data.userName) {
            app.showError('请输入姓名');
            return false;
        }
        if ("" == _this.data.ticketNumber) {
            app.showError('请输入身份证号');
            return false;
        }
        if ("" == _this.data.idNumber) {
            app.showError('请输入手机号');
            return false;
        }
        app._post_form(siteinfo.loginExamination, {
            name: _this.data.userName,
            idNumber: _this.data.idNumber,
            ticketNumber: _this.data.ticketNumber,
            id: _this.data.examinationIdList[_this.data.index]
        }, function (result) {
            wx.setStorageSync('stuInfo', result.data)
            wx.setStorageSync('nowDate', result.data.nowDate)
            wx.setStorageSync('ebatchInfo', _this.data.examinationBatchList[_this.data.index - 1])
            wx.navigateTo({
                url: '/pages/examinationLogin/examinationStart',
            })
        }, function (result) {}, function () {});
    },
    /**
     * 跳转回原页面
     */
    navigateBack: function () {
        // wx.navigateBack();
        wx.navigateBack({
            delta: 2
        })

    },
})